package com.zshan.clinic.web.config;

import com.zshan.clinic.admin.constant.RedisKeyPrefix;
import com.zshan.clinic.web.listener.RedisMessageSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class RedisMessageListenerConfig {

    @Autowired
    private RedisMessageSubscriber redisMessageSubscriber;

    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);

        // 监听一个或多个topic
        container.addMessageListener(redisMessageSubscriber, new PatternTopic(RedisKeyPrefix.TOPIC_CLINIC_CALL_LARGE));

        return container;
    }
}

